cimport c_cv
cimport c_cxcore
cimport cy_cvtypes


#------------ Image Processing -----------------#

def cvCopyMakeBorder(cy_cvtypes.CvArr src, cy_cvtypes.CvArr dst, offset, bordertype, value):
    cdef c_cxcore.CvArr* c_src = src.handle()
    cdef c_cxcore.CvArr* c_dst = dst.handle()
    cdef c_cxcore.CvPoint c_offset = c_cxcore.cvPoint(offset[0], offset[1])
    cdef int c_bordertype = bordertype
    cdef c_cxcore.CvScalar c_value = c_cxcore.cvScalarAll(value) 
    with nogil:
        c_cv.cvCopyMakeBorder(c_src, c_dst, c_offset, c_bordertype, c_value)
    
def cvSmooth(cy_cvtypes.CvArr src, cy_cvtypes.CvArr dst, smoothtype=2,
             size1=3, size2=0, sigma1=0, sigma2=0):
    cdef c_cxcore.CvArr* c_src = src.handle()
    cdef c_cxcore.CvArr* c_dst = dst.handle()
    cdef int c_smoothtype = smoothtype
    cdef int c_size1 = size1
    cdef int c_size2 = size2
    cdef double c_sigma1 = sigma1
    cdef double c_sigma2 = sigma2    
    with nogil:
        c_cv.cvSmooth(c_src, c_dst, c_smoothtype, c_size1, c_size2, c_sigma1, c_sigma2)
                  
def cvFilter2D(cy_cvtypes.CvArr src, cy_cvtypes.CvArr dst, cy_cvtypes.CvMat kernel, anchor):
    cdef c_cxcore.CvArr* c_src = src.handle()
    cdef c_cxcore.CvArr* c_dst = dst.handle()
    cdef c_cxcore.CvMat* c_kernel = kernel.thisptr
    cdef c_cxcore.CvPoint c_anchor = c_cxcore.cvPoint(anchor[0], anchor[1])
    with nogil:
        c_cv.cvFilter2D(c_src, c_dst, c_kernel, c_anchor)
        
def cvIntegral(cy_cvtypes.CvArr image, cy_cvtypes.CvArr sum, cy_cvtypes.CvArr sqsum, cy_cvtypes.CvArr tilted_sum):
    cdef c_cxcore.CvArr* c_image = image.handle()
    cdef c_cxcore.CvArr* c_sum = sum.handle()
    cdef c_cxcore.CvArr* c_sqsum = sqsum.handle()
    cdef c_cxcore.CvArr* c_tilted_sum = tilted_sum.handle()
    with nogil:
        c_cv.cvIntegral(c_image, c_sum, c_sqsum, c_tilted_sum)
        
def cvPyrDown(cy_cvtypes.CvArr src, cy_cvtypes.CvArr dst, filter):
    cdef c_cxcore.CvArr* c_src = src.handle()
    cdef c_cxcore.CvArr* c_dst = dst.handle()
    cdef int c_filter = filter
    with nogil:
        c_cv.cvPyrDown(c_src, c_dst, c_filter)
        
def cvPyrUp(cy_cvtypes.CvArr src, cy_cvtypes.CvArr dst, filter):
    cdef c_cxcore.CvArr* c_src = src.handle()
    cdef c_cxcore.CvArr* c_dst = dst.handle()
    cdef int c_filter = filter
    with nogil:
        c_cv.cvPyrUp(c_src, c_dst, c_filter)
        
def cvWatershed(cy_cvtypes.CvArr image, cy_cvtypes.CvArr markers):
    cdef c_cxcore.CvArr* c_image = image.handle()
    cdef c_cxcore.CvArr* c_markers = markers.handle()
    with nogil:
        c_cv.cvWatershed(c_image, c_markers)
        
def cvInpaint(cy_cvtypes.CvArr src, cy_cvtypes.CvArr inpaint_mask, cy_cvtypes.CvArr dst, inpaintRange, flags):
    cdef c_cxcore.CvArr* c_src = src.handle()
    cdef c_cxcore.CvArr* c_inpaint_mask = inpaint_mask.handle()
    cdef c_cxcore.CvArr* c_dst = dst.handle()
    cdef double c_inpaintRange = inpaintRange
    cdef int c_flags = flags
    with nogil:
        c_cv.cvInpaint(c_src, c_inpaint_mask, c_dst, c_inpaintRange, c_flags)
        
def cvSobel(cy_cvtypes.CvArr src, cy_cvtypes.CvArr dst, xorder, yorder, aperture_size):
    cdef c_cxcore.CvArr* c_src = src.handle()
    cdef c_cxcore.CvArr* c_dst = dst.handle()
    cdef int c_xorder = xorder
    cdef int c_yorder = yorder
    cdef int c_aperture_size = aperture_size
    with nogil:
        c_cv.cvSobel(c_src, c_dst, c_xorder, c_yorder, c_aperture_size)
        
def cvLaplace(cy_cvtypes.CvArr src, cy_cvtypes.CvArr dst, aperture_size):
    cdef c_cxcore.CvArr* c_src = src.handle()
    cdef c_cxcore.CvArr* c_dst = dst.handle()
    cdef int c_aperture_size = aperture_size
    with nogil:
        c_cv.cvLaplace(c_src, c_dst, c_aperture_size)
        
def cvCvtColor(cy_cvtypes.CvArr src, cy_cvtypes.CvArr dst, code):
    cdef c_cxcore.CvArr* c_src = src.handle()
    cdef c_cxcore.CvArr* c_dst = dst.handle()
    cdef int c_code = code
    with nogil:
        c_cv.cvCvtColor(c_src, c_dst, c_code)
        
def cvResize(cy_cvtypes.CvArr src, cy_cvtypes.CvArr dst, interpolation):
    cdef c_cxcore.CvArr* c_src = src.handle()
    cdef c_cxcore.CvArr* c_dst = dst.handle()
    cdef int c_interpolation = interpolation
    with nogil:
        c_cv.cvResize(c_src, c_dst, c_interpolation)
        
def cvWarpAffine(cy_cvtypes.CvArr src, cy_cvtypes.CvArr dst, cy_cvtypes.CvMat map_matrix, flags, fillval):
    cdef c_cxcore.CvArr* c_src = src.handle()
    cdef c_cxcore.CvArr* c_dst = dst.handle()
    cdef c_cxcore.CvMat* c_map_matrix = map_matrix.thisptr
    cdef int c_flags = flags
    cdef c_cxcore.CvScalar c_fillval = c_cxcore.cvScalarAll(fillval)
    with nogil:
        c_cv.cvWarpAffine(c_src, c_dst, c_map_matrix, c_flags, c_fillval)
        
def cvWarpPerspective(cy_cvtypes.CvArr src, cy_cvtypes.CvArr dst, cy_cvtypes.CvMat map_matrix, flags, fillval):
    cdef c_cxcore.CvArr* c_src = src.handle()
    cdef c_cxcore.CvArr* c_dst = dst.handle()
    cdef c_cxcore.CvMat* c_map_matrix = map_matrix.thisptr
    cdef int c_flags = flags
    cdef c_cxcore.CvScalar c_fillval = c_cxcore.cvScalarAll(fillval)
    with nogil:
        c_cv.cvWarpPerspective(c_src, c_dst, c_map_matrix, c_flags, c_fillval)
        
def cvRemap(cy_cvtypes.CvArr src, cy_cvtypes.CvArr dst, cy_cvtypes.CvArr mapx, cy_cvtypes.CvArr mapy, flags, fillval):
    cdef c_cxcore.CvArr* c_src = src.handle()
    cdef c_cxcore.CvArr* c_dst = dst.handle()
    cdef c_cxcore.CvArr* c_mapx = mapx.handle()
    cdef c_cxcore.CvArr* c_mapy = mapy.handle()
    cdef int c_flags = flags
    cdef c_cxcore.CvScalar c_fillval = c_cxcore.cvScalarAll(fillval)
    with nogil:
        c_cv.cvRemap(c_src, c_dst, c_mapx, c_mapy, c_flags, c_fillval)
        
def cvConvertMaps(cy_cvtypes.CvArr mapx, cy_cvtypes.CvArr mapy, cy_cvtypes.CvArr mapxy, cy_cvtypes.CvArr mapalpha):
    cdef c_cxcore.CvArr* c_mapx = mapx.handle()
    cdef c_cxcore.CvArr* c_mapy = mapy.handle()
    cdef c_cxcore.CvArr* c_mapxy = mapxy.handle()
    cdef c_cxcore.CvArr* c_mapalpha = mapalpha.handle()
    with nogil:
        c_cv.cvConvertMaps(c_mapx, c_mapy, c_mapxy, c_mapalpha)
        
        


#-------------- Histogram Functions -------------------#


        


        
